<?php 
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Job;
use yii\data\Pagination;

/**
* 职位
*/
class JobController extends Controller
{
	public $layout='my';
	public function actionJob(){
		$model=new Job();
		$request=Yii::$app->request;
		if($request->isPost){
			$post=$request->post();
			if($model->load($post)){
				$res=$model->save();
				if($res){
					return $this->redirect('?r=job/job_show');
				}
			}
		}
		return $this->render('job',['model'=>$model]);
	}
	//展示职位
	public function actionJob_show(){
		$query = Job::find();
        $pagination = new Pagination(['defaultPageSize' => 5,'totalCount' => $query->count()]);
        $res = $query->offset($pagination->offset)->limit($pagination->limit)->all();

        return $this->render('job_show', ['res' => $res,'pagination' => $pagination]);

		/*$model=new Job();
		$res=$model->find()->all();
		return $this->render('job_show',['res'=>$res]);*/
	}
	//删除
	public function actionJob_del(){
		$model=new Job();
		$JId=$_GET['JId'];
		$res=$model->deleteAll("JId=$JId");
		if($res){
			return $this->redirect('?r=job/job_show');
		}
	}
	//修改
	public function actionJob_upd(){
		$model=new Job();
		$JId=$_GET['JId'];
		$res=$model->find()->where(['JId'=>$JId])->one();
		if($res){
			return $this->render('job_upds',['res'=>$res]);
		}
	}
	//修改
	public function actionJob_upds(){
		$model = new Job();
		$request = Yii::$app->request;
		if($request->isPost){
			$post=$request->post();
			$JId=$post['Job']['JId'];
			$model=$model->find()->where(['JId'=>$JId])->one();
			if($model->load($post) && $model->validate()){
				$res=$model->save();
				if($res){
					return $this->redirect('?r=job/job_show');
				}
			}
		}
	} 
}



 ?>